package com.ruoyi.web.controller.system;

import java.util.List;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.BgPhoto;
import com.ruoyi.system.service.IBgPhotoService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 官网背景图Controller
 * 
 * @author ruoyi
 * @date 2021-03-04
 */
@Api(value = "背景图后管",tags = "背景图后管",description = "背景图后管")
@Controller
@RequestMapping("/yct/bgphoto")
public class BgPhotoController extends BaseController
{
    private String prefix = "yct/bgphoto";

    @Autowired
    private IBgPhotoService bgPhotoService;

    @RequiresPermissions("yct:bgphoto:view")
    @GetMapping()
    public String bgphoto()
    {
        return prefix + "/bgphoto";
    }

    /**
     * 查询官网背景图列表
     */
    @ApiOperation(value = "查询背景图列表",notes = "查询背景图列表")
    @RequiresPermissions("yct:bgphoto:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BgPhoto bgPhoto)
    {
        startPage();
        List<BgPhoto> list = bgPhotoService.selectBgPhotoList(bgPhoto);
        return getDataTable(list);
    }

    /**
     * 导出官网背景图列表
     */
    @ApiOperation(value = "导出背景图列表",notes = "导出背景图列表")
    @RequiresPermissions("yct:bgphoto:export")
    @Log(title = "官网背景图", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BgPhoto bgPhoto)
    {
        List<BgPhoto> list = bgPhotoService.selectBgPhotoList(bgPhoto);
        ExcelUtil<BgPhoto> util = new ExcelUtil<BgPhoto>(BgPhoto.class);
        return util.exportExcel(list, "bgphoto");
    }

    /**
     * 新增官网背景图
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存官网背景图
     */
    @ApiOperation(value = "新增保存背景图",notes = "新增保存背景图")
    @RequiresPermissions("yct:bgphoto:add")
    @Log(title = "官网背景图", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BgPhoto bgPhoto)
    {
        return toAjax(bgPhotoService.insertBgPhoto(bgPhoto));
    }

    /**
     * 修改官网背景图
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        BgPhoto bgPhoto = bgPhotoService.selectBgPhotoById(id);
        mmap.put("bgPhoto", bgPhoto);
        return prefix + "/edit";
    }

    /**
     * 修改保存官网背景图
     */
    @ApiOperation(value = "修改保存背景图",notes = "修改保存背景图")
    @RequiresPermissions("yct:bgphoto:edit")
    @Log(title = "官网背景图", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BgPhoto bgPhoto)
    {
        return toAjax(bgPhotoService.updateBgPhoto(bgPhoto));
    }

    /**
     * 删除官网背景图
     */
    @ApiOperation(value = "删除背景图",notes = "删除背景图")
    @RequiresPermissions("yct:bgphoto:remove")
    @Log(title = "官网背景图", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(bgPhotoService.deleteBgPhotoByIds(ids));
    }
}
